import config from './config'

let baseURL ;
//获取设备信息
let device = uni.getSystemInfoSync().platform
//小程序 devtools
if (device === "devtools") {
	baseURL = config.mpHost
	//process.env.NODE_ENV  环境变量
} else if ((device === "ios" || device === "android") && process.env.NODE_ENV === "development") {
	baseURL = config.h5Host
}


export default function(url, data = {}, method = "GET") {
	console.log(device);
	console.log(process.env.NODE_ENV);
	return new Promise((resolve, reject) => {
		uni.request({
			// url:'http://127.0.0.1:3002'+url,
			// url:"/api"+url, 解决跨域
			url: baseURL + url,
			data,
			method,
			header:{
				"token":uni.getStorageSync('openId')
			},
			success(res) {
				resolve(res.data)
			},
			fail(error) {
				// reject(error)
				//假成功
				resolve(false)
			}
		})
	})
}
